//
//  QDSDCycleViewTableViewCell.m
//  QDMetroClient
//
//  Created by YueWen on 2019/1/18.
//  Copyright © 2019 YueWen. All rights reserved.
//

#import "QDSDCycleViewTableViewCell.h"

@implementation QDSDCycleViewTableViewCell


- (void)buildView {
    
    self.cycleContentInsets = UIEdgeInsetsZero;
    [self.contentView addSubview:self.cycleView];
    [self makeCycleViewConstraints:self.cycleView];
}


- (void)makeCycleViewConstraints:(RITLSDCycleScrollView *)view {
    
    if (!view.superview) { return; }
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(self.cycleContentInsets.left);
        make.top.offset(self.cycleContentInsets.top);
        make.right.inset(self.cycleContentInsets.right);
        make.bottom.inset(self.cycleContentInsets.bottom);
    }];
}

#pragma mark - <RITLSDCycleScrollViewDataSource>

- (Class)cycleViewCustomCollectionViewCellClass:(RITLSDCycleScrollView *)cycleView {
    return SDCollectionViewCell.class;
}


- (NSDictionary<NSString *,Class> *)cycleViewAllRegisterCellClasses:(RITLSDCycleScrollView *)cycleView {
    
    if (!self.configCellConfiguration) { return nil; }
    return self.configCellConfiguration(cycleView);
}


- (NSString *)cycleViewIdentifer:(RITLSDCycleScrollView *)cycleView atIndexPath:(NSIndexPath *)indexPath {
    
    if (!self.configCellIdentifierHandler) return nil;
    return self.configCellIdentifierHandler(cycleView,indexPath);
}


- (void)cycleView:(RITLSDCycleScrollView *)cycleView setupCustomCell:(UICollectionViewCell<RITLSDCycleScrollViewCell> *)cell forIndex:(NSIndexPath *)indexPath {
    
    if (!self.customHandler) { return; }
    self.customHandler(cycleView, cell, indexPath);
}

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    
    if (!self.selectHandler) { return; }
    self.selectHandler(cycleScrollView, index);
}


#pragma mark - Lazy

- (RITLSDCycleScrollView *)cycleView {
    
    if (!_cycleView) {
        
        RITLSDCycleScrollView *view = [RITLSDCycleScrollView new];
        view.dataSource = self;
        view.delegate = self;
        view.backgroundColor = UIColor.whiteColor;
        
        view.autoScroll = false;
        view.infiniteLoop = false;
        view.contentView.pagingEnabled = false;
        
        _cycleView = view;
    }
    
    return _cycleView;
}

@end
